class Solution {
public:
    int minimumSumSubarray(vector<int>& nums, int l, int r) {
        const int n = nums.size();
        int PreSum[n];
        memset(PreSum, 0, sizeof(PreSum));

        int sum = 0, ans = INT_MAX;
        for(int i = 0; i < n; ++i)
        {
            sum += nums[i];
            PreSum[i] = sum;
        }

        int p = 0, window = 0;
        for(int i = 0; i < n; ++i)
        {
            for(int j = l; j <= r; ++j)
            {
                p = i + j - 1;
                if(p < n)
                {
                    window = PreSum[p] - PreSum[i] + nums[i];
                    if(window > 0)
                        ans = min(ans, window);
                }
            }
        }

        return ans == INT_MAX ? -1 : ans;
    }
};
